package com.gmadmin.gmmbg;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.gmadmin.gmmbg.entity.BaseEntity;

import java.util.Collections;

/**
 * 用于生产MBG的代码
 * Created by michael on 2018/4/26.
 */
public class Generator {
    public static void main(String[] args) {
        String url = "jdbc:mysql://127.0.0.1:3306/gm_admin?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai";
        String username = "root";
        String password = "123456";
        String outFile = "E:\\workspace\\idea-workspace-gitlab\\2025\\gm-admin\\gm-mbg\\src\\main";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("micheal yang") // 设置作者
                            .enableSpringdoc()   // 开启spring doc注解
                            .outputDir(outFile + "/java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.gmadmin.gmmbg") // 设置父包名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, outFile + "/resources/mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder()
                            .superClass(BaseEntity.class)
                            .enableChainModel()
                            .enableLombok()
                            .logicDeleteColumnName("del_flag")  //逻辑删除字段
                            .logicDeletePropertyName("delFlag")
                            .addSuperEntityColumns("id", "create_by", "create_time", "update_by", "update_time", "del_flag")
                            .build();
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
